
package com.cqwu.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.cqwu.bean.Person;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author LK
 * @time  2015-11-28 下午1:19:44
 */
public class testJSON {

	
	public static void main(String[] args) {
		
		//List ---> JSON
 		List list = new ArrayList();
 		list.add(new Person("likang", 21, "男"));
		list.add(new Person("lisi",10, "女"));
		list.add(new Person("haha", 54, "男"));
		JSONArray jsonArray = JSONArray.fromObject(list);
		for (int i = 0; i < jsonArray.size(); i++) {
			System.out.println(jsonArray.get(i));
		}
		System.out.println("=======================");
		
	/*	//Map ---> JSON
		Map map = new HashMap();
		map.put(1, "test1");
		map.put(2, new String[]{"11","22","33"});
		map.put(3, "test3");
		JSONObject jsonObject = JSONObject.fromObject(map);
		System.out.println(jsonObject.toString());
		Iterator it1 = jsonObject.keys();
		while(it1.hasNext()){
			Object obj = jsonObject.get(it1.next());
			System.out.println(obj.toString());
		}
		System.out.println("===============");
		
		//string --> JSON
		JSONArray jsa = JSONArray.fromObject("['aa','bb','cc']");
		System.out.println(jsa.toString());
		Iterator it3 = jsa.iterator();
		while(it3.hasNext()){
			System.out.println(it3.next());
		}
		*/
	}
	
}
